package models

import (
	"time"
)

// User 用户模型
type User struct {
	ID        uint      `json:"id" gorm:"primaryKey"`
	Username  string    `json:"username" gorm:"column:username;unique;not null"`
	Password  string    `json:"password,omitempty" gorm:"column:password;not null"`
	Name      string    `json:"name" gorm:"column:name"`
	Role      string    `json:"role" gorm:"column:role;default:admin"`
	Status    int       `json:"status" gorm:"column:status;default:1"`
	LastLogin *time.Time `json:"last_login" gorm:"column:last_login"`
	CreatedAt time.Time `json:"created_at" gorm:"column:created_at;autoCreateTime"`
	UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at;autoUpdateTime"`
}

// TableName 指定表名
func (User) TableName() string {
	return "users"
}

// LoginRequest 登录请求
type LoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

// LoginResponse 登录响应
type LoginResponse struct {
	Token     string `json:"token"`
	Username  string `json:"username"`
	Name      string `json:"name"`
	Role      string `json:"role"`
}